<include file="__THEME__/public_header" />
<include file="__THEME__/editor" />
<script type="text/javascript" src="__APP__/Js/common.js"></script>
<script type="text/javascript" src="__APP__/Js/topic.js"></script>
<link  href="__APP__/group.css" rel="stylesheet" type="text/css"/>
<style>
    .sk_main{background-color: transparent;}
    .internalBox{width: 1200px;margin: 0 auto;background-color: #fff;zoom: 1;}
    .internalBox:after{clear: both;display: block;height: 0;visibility: visible;content: "";}
    .breadInter{width: 1200px;margin: 0 auto;}
    .sk_main .sk_r{width: 315px;}
</style>
<script>
var gid = {$gid};
var tid = {$tid};

var admin_set = function(op)
{
	$.ajax({
		type: "POST",
		url:  "__URL__&{:C('VAR_ACTION')}="+op,
		data: 'gid={$gid}&tid={$tid}&op=' + op,
		dataType:"json",
		success: function(data)
		{
			if (data.flag == 1) {
				var element_id = '';
				var operation = '';
				var operation_title = '';
				switch (op) {
					case 'lock':
						element_id = 'lock';
						operation = 'unlock';
						operation_title = '取消锁定';
						$('#lock_icon').show();
						break;
					case 'unlock':
						element_id = 'lock';
						operation = 'lock';
						operation_title = '锁定';
						$('#lock_icon').hide();
						break;
					case 'dist': // 设为精华
						element_id = 'dist';
						operation = 'undist';
						operation_title = '取消精华';
						$('#dist_icon').show();
						break;
					case 'undist': // 取消精华
						element_id = 'dist';
						operation = 'dist';
						operation_title = '设为精华';
						$('#dist_icon').hide();
						break;
					case 'top': // 置顶
						element_id = 'top';
						operation = 'untop';
						operation_title = '取消置顶';
						$('#top_icon').show();
						break;
					case 'untop': // 取消置顶
						element_id = 'top';
						operation = 'top';
						operation_title = '置顶';
						$('#top_icon').hide();
						break;
				}
				var obj = $('#'+element_id);
				obj.html(operation_title);
				obj.attr('title', operation_title);
				obj.attr('href', 'javascript:admin_set("'+operation+'");');
				ui.success("操作成功");
			}else {
				ui.error("操作失败");
			}
		}
	});
}

var quote = function(id)
{
	ui.box.load(U('group/Topic/quoteDialog') + '&gid=' + gid + '&id=' + id,{title:'引用'});
}

	function reload() {
		window.location.reload();
	}
	
	function delThread(gid, tid)
   {

		if (confirm("删除后无法恢复！确认删除整个话题？"))
		{
			document.delform.gid.value = gid;
			document.delform.tid.value = tid;
			document.delform.type.value = 'thread';
			document.delform.submit();
		}
	}
	function delPost(gid,pid)
	{
		if (confirm("删除后无法恢复！确认删除该条回复？"))
		{
			document.delform.gid.value = gid;
			document.delform.tid.value = pid;
			document.delform.type.value = 'post';
			document.delform.submit();
		}
	}

</script>
<div class="breadcrumb">
    <div class="breadInter">
        <a href="{:U('group')}" style="padding-left:0;">小组</a>&gt;<a href="{:U('group/Topic/index',array('gid'=>$gid))}">{$groupinfo.name}</a>&gt;
        <a>《{$topic.ctitle}{$topic.title}》</a>
    </div>

</div>
 
 
 <div class="sk_main">
     <div class="internalBox">
         <div class="sk_l">
             <div class="sk_avator"><space uid="topic['uid']" class="fn" target="_blank">{uavatar}</space><p> <space uid="topic['uid']" class="fn nogroup" target="_blank">{uname}</space></p></div>
             <h1>{$topic.ctitle}{$topic.title}</h1>
             <div class="sk_dig">{$topic['addtime']|friendlyDate} 来自小组</div>
             <div class="sk_cont">
                 {$topic.content|html_entity_decode=###, ENT_QUOTES, 'UTF-8'}
             </div>
             <php> if($topic['mtime']) { </php>
             <php>} </php>
             <div class="lh35 alR toplineD">
                 <php>if($isadmin) { </php>
                 <php>if($topic['dist'] == 1) {</php>
                 <a id="dist" href="javascript:admin_set('undist');" title="取消精华">取消精华</a> 
                 <php>} else {</php>
                 <a id="dist" href="javascript:admin_set('dist');" title="设为精华">设为精华</a>
                 <php>}</php>
                 <span class="line_l">|</span>
                 <php>if($topic['top'] == 1) {</php>
                 <a id="top" href="javascript:admin_set('untop');" title="取消置顶">取消置顶</a> 
                 <php>} else {</php>
                 <a id="top" href="javascript:admin_set('top');" title="置顶">置顶</a>
                 <php>}</php>
                 <span class="line_l">|</span>
                 <php>if($topic['lock'] == 1) {</php>
                 <a id="lock" href="javascript:admin_set('unlock');" title="取消锁定">取消锁定</a> 
                 <php>} else {</php>
                 <a id="lock" href="javascript:admin_set('lock');" title="锁定">锁定</a>
                 <php>}</php>
                 <span class="line_l">|</span>
                 <a href="{:U('/Topic/edit',array('gid'=>$gid,'tid'=>$tid))}" title="编辑">编辑</a>
                 <span class="line_l">|</span>  <a href="javascript:delThread({$gid},{$tid});" title="删除">删除</a> <span class="line_l">|</span>
                 <php>} else if ($mid == $topic['uid']) { </php>
                 <a href="{:U('/Topic/edit',array('gid'=>$gid,'tid'=>$tid))}" title="编辑">编辑</a> <span class="line_l">|</span>
                 <a href="javascript:delThread({$gid},{$tid});" title="删除">删除</a> <span class="line_l">|</span>
                 <php>}</php>
                 <php>if ($ismember) { </php>
                 <a href="#replyForm" onclick="postquotes({$topic['pid']})">引用</a>
                 <php>}</php>
             </div>
             <div class="reply feed_list">
                 {:W('Comment',array('tpl'=>'detail', 'table'=>'group_topic', 'row_id'=>$topic[id], 'canrepost'=>'0', 'cancomment'=>1, 'cancomment_old'=>0, 'showlist'=>1, 'limit'=>'20', 'order'=>'DESC'))}
             </div>
         </div>
         <div class="sk_r">
             <h1>作者的其他帖子</h1>
             <ul>
                 <volist name="otherThread" id="v">
                     <li><a href="{:U('/Topic/topic',array('gid'=>$gid,'tid'=>$v['id']))}" target="_blank">{$v.ctitle}{$v.title}</a></li>
                 </volist>
             </ul>
             <h1>最新帖子</h1>
             <ul>
                 <volist name="hotThread" id="v">
                     <li><a href="{:U('/Topic/topic',array('gid'=>$gid,'tid'=>$v['id']))}" target="_blank">{$v.ctitle}{$v.title}</a></li>
                 </volist>
             </ul>
         </div>
     </div>
 </div>
<div class="content_holder" style="display:none">
<div class="content no_bg boxShadow"> 
	<include file="../Public/_mainNav" />
  <!-- 内容 begin  -->
  <div class="main no_l"> 
    <!-- 右侧内容 begin  -->
    <div class="mainbox"> <include file="../Public/_groupInfo" />
      <div id="col5" class="st-index-main">
      	<div class="extend-foot">
      <include file="../Public/top" />
        <form name="delform" action="{:U('group/Topic/del')}" method="post">
          <input type=hidden name=gid value="{$gid}">
          <input type=hidden name=tid value="{$tid}">
          <input type=hidden name=type value="">
        </form>
        <div class="groupBox mLR15">
          <volist name="postlist['data']" id="post" key="key">
            <if condition="$post['istopic'] eq 1">              
              <h3 class="group_Posts_tit">
              <span class="right f12"> {:W('ShareToFeed',array('title'=>'分享群组帖子','initHTML'=>urlencode('分享来自群组“'.$groupinfo['name'].'”的帖子“'.$topic['title'].'”'),'url'=>U('group/Topic/topic',array('gid'=>$gid,'tid'=>$topic['id'])),'from'=>'grouptopic'))}</span>
              <span><span class="sd" id="lock_icon" <php>if(!$topic['lock']){</php>style="display:none;"<php>}</php>>锁</span><span class="jh" id="dist_icon" <php>if(!$topic['dist']){</php>style="display:none;"<php>}</php>>精</span><span class="zd" id="top_icon" <php>if(!$topic['top']){</php>style="display:none;"<php>}</php>>顶</span><span style="float:left">{$topic.ctitle}{$topic.title}</span></span>
              </h3>
              <div class="mb20" style="border-bottom:2px solid #E6E6E6;">
                <div class="left" style="width:60px;"><span class="headpic50"><space uid="topic['uid']" target="_blank">{uavatar=m}</space></span><br />
                </div>
                <div style="margin-left:70px">
                  <div class="cGray2">
                    <div class="right">楼主</div>
                    <space uid="topic['uid']" class="fn" target="_blank">{uname}</space> <em>{$topic['addtime']|friendlyDate}</em></div>
                  <div class="pb10 pt10 f14px" style="padding-bottom:50px" >
                    <div id="topic_content" class="topic-content">{$topic.content|html_entity_decode=###, ENT_QUOTES, 'UTF-8'}</div>
                    <php>if (is_array($topic['attach'])) {</php>
                      <if condition="!$groupinfo['openUploadFile']">
                      	<div>文件共享已关闭</div>
                      <elseif condition="($groupinfo['whoUploadFile'] == 3 && !$ismember) || ($groupinfo['whoUploadFile'] == 2 && !$isadmin)" />
                      	<div class="locked">无权限查看附件</div>
                      <else />
                      <volist name="topic['attach']" id="data">
                        <div class="adjunct_list">
                          <div class="Annex">
                            <if condition="$data['is_del']">
                              <span style="text-decoration:line-through;">附件：{$data['name']}</span>[<span style="color:#FF0000;">已被管理员删除</span>]
                            <else />
                          	    附件：<a href="javascript:download({$data['id']});" <if condition="$file['note']">title="注释：{$data['note']}"</if>>{$data['name']}</a>
                            </if>
                          </div>
                        </div>
                      </volist>
                      </if>
                    <php>}</php>
                  </div>
                  <php> if($topic['mtime']) { </php>
                  <div class="lh35 alR cGray2">修改于{$topic['mtime']|friendlyDate}</div>
                  <php>} </php>
                  <div class="lh35 alR toplineD">
                    <php>if($isadmin) { </php>
	                    <php>if($topic['dist'] == 1) {</php>
	                   		<a id="dist" href="javascript:admin_set('undist');" title="取消精华">取消精华</a> 
	                    <php>} else {</php>
	                    	<a id="dist" href="javascript:admin_set('dist');" title="设为精华">设为精华</a>
	                    <php>}</php>
	                    <span class="line_l">|</span>
	                    <php>if($topic['top'] == 1) {</php>
	                    	<a id="top" href="javascript:admin_set('untop');" title="取消置顶">取消置顶</a> 
	                    <php>} else {</php>
	                    	<a id="top" href="javascript:admin_set('top');" title="置顶">置顶</a>
	                    <php>}</php>
	                    <span class="line_l">|</span>
	                    <php>if($topic['lock'] == 1) {</php>
	                    	<a id="lock" href="javascript:admin_set('unlock');" title="取消锁定">取消锁定</a> 
	                    <php>} else {</php>
	                    	<a id="lock" href="javascript:admin_set('lock');" title="锁定">锁定</a>
	                    <php>}</php>
	                    <span class="line_l">|</span>
	                    <a href="{:U('/Topic/edit',array('gid'=>$gid,'tid'=>$tid))}" title="编辑">编辑</a>
	                    <span class="line_l">|</span>  <a href="javascript:delThread({$gid},{$tid});" title="删除">删除</a> <span class="line_l">|</span>
                    <php>} else if ($mid == $topic['uid']) { </php>
                        <a href="{:U('/Topic/edit',array('gid'=>$gid,'tid'=>$tid))}" title="编辑">编辑</a> <span class="line_l">|</span>
                        <a href="javascript:delThread({$gid},{$tid});" title="删除">删除</a> <span class="line_l">|</span>
                    <php>}</php>
                    <php>if ($ismember) { </php>
                      <a href="#replyForm" onclick="postquotes({$topic['pid']})">引用</a>
                    <php>}</php>
                  </div>
                  <!-- 引用begin -->
                  <div id="quotes_{$topic.pid}" style="display:none;">
                  <div class="g_quotes" style="width:560px;height:120px;overflow:auto;text-align:left;margin:20px 0 20px 70px;*width:550px;">
				   <h5>引用：</h5>
				   <em>  <a href="#quotes_{$topic.pid}" onclick="postquotes()" class="right">取消引用</a>原帖由 <space uid="topic[uid]" class="fn" target="_blank">@{uname}</space> 于{$topic['addtime']|friendlyDate}发表</em>
				   {$topic['content']|html_entity_decode=###, ENT_QUOTES, 'UTF-8'}
				   			<input type="hidden" value="{$topic.pid}" name="qid" id="qid">
							<input type="hidden" value="{$gid}" name="gid">
							<input type="hidden" value="1" name="quote">
							<input type="hidden" value="{$topic['id']}" name="tid">
					</div></div>
					<!-- 引用end -->
                </div>
              </div>
              <else />
              <div style="margin:0 0 20px 0;overflow:hidden;*zoom:1;_width:99%;">
                <div class="left f14px cGray2" style="width:60px; ">
                  <span style="font-size:24px"><php>echo $start_floor;$start_floor++</php></span> 楼
                </div>
                <div style="margin-left:70px">                
                  <div class="cGray2 lh30">                    
                    <span class="pic30"><space uid="post['uid']" target="_blank">{uavatar=m}</space></span>
                   <space uid="post['uid']" class="fn" target="_blank">{uname}</space>
                  {$post['usergroupicon']} {$post['ctime']|friendlyDate}</div>
                  <div class="btmlineD pb10 pt10 f14px">
                    <div style="padding:0 50px 0 0; " id="reply_content" class="reply-content">
                      <php>if($post['quote']){ $qcontent = getPost($post['quote']);</php>
                      <div id="quotes" class="g_quotes">
                       <h5>引用：</h5>
                       <em>原帖由 <space uid="qcontent[uid]" class="fn" target="_blank">@{uname}</space> 于{$qcontent['ctime']|friendlyDate}发表</em>
                        {$qcontent['content']|html_entity_decode=###, ENT_QUOTES, 'UTF-8'}
                      </div>
                      <php>}</php>
                      {$post['content']|html_entity_decode=###, ENT_QUOTES, 'UTF-8'}
                    </div>
                  </div>
                  <div>
                  <!-- 引用内容begin -->
                  <div id="quotes_{$post.id}" style="display:none;">
	                  <div class="g_quotes" style="width:560px;height:120px;overflow:auto;text-align:left;margin:20px 0 20px 70px;*width:550px;">
					   <h5>引用：</h5>
					   <em><a href="#quotes_{$post.id}" onclick="postquotes()" class="right">取消引用</a>原帖由 <space uid="post[uid]" class="fn" target="_blank">@{uname}</space> 于{$post['ctime']|friendlyDate}发表</em>
					   {$post['content']|html_entity_decode=###, ENT_QUOTES, 'UTF-8'}
					   			<input type="hidden" value="{$post.id}" name="qid" id="qid">
								<input type="hidden" value="{$gid}" name="gid">
								<input type="hidden" value="1" name="quote">
								<input type="hidden" value="{$post['tid']}" name="tid">							
						</div>
					</div>
					<!-- 引用内容end -->
                  </div>
                  <php>if ($ismember) { </php>
                    <div class="lh35 alR">
                    <php>if($mid == $post['uid'] || $isadmin){</php>
                      <a href="{:U('/Topic/editPost',array('gid'=>$gid,'pid'=>$post['id']))}">编辑</a><span class="line_l">|</span>
                      <a href="javascript:delPost({$gid},{$post['id']});">删除</a><span class="line_l">|</span>
                    <php>}</php>
                    <a href="#replyForm" onclick="postquotes({$post['id']})">引用</a>
                    </div>
                  <php>}</php>
                </div>
              </div>
            </if>
          </volist>
          <if condition="$postlist['html']"><div class="page">{$postlist['html']}</div></if>
          <php>if($topic['lock'] == 0){</php>
          <div class="li mt10 clearfix">
			  <form method="post" action="{:U('group/Topic/post')}" onbeforesubmit="replySubmit();" id="replyForm">
				<div id="postquotes">
				
				</div>
				<div class="left alR lh25" style="width:70px"><strong>回复帖子：</strong></div>
				<div style="margin-left:70px;">
            	   {:W('Editor',array('contentName'=>'content','value'=>''))}
				</div>

           		<div style="margin-left:70px;margin-top:10px">			    
                <input type="hidden" name="gid" value="{$gid}">
				<input type="hidden" name="tid" value="{$tid}">
				<input type="submit" class="btn_b mt5"  value="发表" id="send_reply" />
			   </div>
			  </form>
          </div>
          <php>} else {</php>
          	<div class="li mt10 clearfix">
			  <form method="post" action="{:U('group/Topic/post')}" id="replyForm">
				<div class="left alR lh25" style="width:70px"><strong>回复帖子：</strong></div>
				<div style="margin-left:70px;">
                <div style="background-color:#F8F8F8; border:1px solid #EBEBEB; -moz-border-radius: 3px;-khtml-border-radius: 3px;-webkit-border-radius: 3px;border-radius: 3px; padding:50px 0; color:#666666; text-align:center;">本贴已锁定暂时不能回复</div>
                </div>
              </form>
          <php>}</php>
          </div>
        </div>
      </div>
      </div>
      <div class="c"></div>
    </div>
  </div>
</div>
</div>
<script>
function postquotes(id){
	if ( !id ){
		$('#postquotes').html('');
		return;
	}
	var quoteshtml = $('#quotes_'+id).html();
	$('#postquotes').html(quoteshtml);
}
function download(fid) {
	if (!fid) {
		ui.error('附件参数错误');
		return false;
	}
	document.downloadform.fid.value = fid; 
	document.downloadform.submit();
}
function photo_size(name){
	$(name+" img").each(function(){
		var width = 500;
		var height = 500;
		var image = $(this);
		if (image.width() > image.height()){
		   if(image.width()>width){
			image.width(width);
			image.height(width/image.width()*image.height());
		   }
		}
		else{
		   if(image.height()>height){
			image.height(height);
			image.width(height/image.height()*image.width());
		   }
		}
		  image.addClass('hand');
		  image.bind('click',function(){
                   window.open(image.attr('src'),'_blank');
                });
	});
}

photo_size('#topic_content');
photo_size('#reply_content');
photo_size('#quotes');

<php>if($topic['lock'] == 0){</php>
function replySubmit() {
	var content = E.getData();
    content = removeHTMLTag(content);
	if(checkPostContent(content) < 10) {
		ui.error('回复内容不能小于10个字');
		return false;
	}
	return true;
}

<php>}</php>
</script> 
<include file="__THEME__/public_footer" />